/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package maxent.mr.mapred;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Mapper;
import stanford.tagger.LambdaSolveTagger;


/**
 *
 * @author hadoop
 */
public class IISMapper
            extends Mapper<IntWritable, DoubleWritable, IntWritable, DoubleWritable>{

    private LambdaSolveTagger prob;

    @Override
    public void setup(Context context) throws IOException{
        
        try {
                ObjectInputStream is = new ObjectInputStream(new FileInputStream("targets"));
                prob = (LambdaSolveTagger) is.readObject();
                System.out.println(prob.p.functions.get(1).ftilde());
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e); // bizarre!
            }
    }

    @Override
    public void map(IntWritable key, DoubleWritable value, Context context) throws IOException, InterruptedException{

        double deltaL = 0.0;
        deltaL = prob.newton(deltaL, key.get(), prob.eps);
        context.write(key, new DoubleWritable(deltaL));
        
    }

    
    
}
